import { request } from "@/utils/service"
interface PageParam {
  pageNum: number
  pageSize: number
}
export interface UserPageParam extends PageParam {
  name?: string
  phone?: number | null
}
interface PageResponse<T> {
  size: number
  current: number
  total: number
  records: T[]
}
interface Response<T> {
  code: number
  msg: string
  data: T
}
export function getUserList(params: UserPageParam): Promise<Response<PageResponse<any>>> {
  return request({
    url: "user/list",
    method: "get",
    params: params
  })
}
export function putDisable(uId: string): Promise<Response<null>> {
  return request({
    url: `user/disable/${uId}`,
    method: "put"
  })
}
export function putUnDisable(uId: string): Promise<Response<null>> {
  return request({
    url: `user/unDisable/${uId}`,
    method: "put"
  })
}
export interface BookPageParam extends PageParam {
  name?: string
  title?: string
}
export function getBookList(param: BookPageParam): Promise<Response<PageResponse<any>>> {
  return request({
    url: "book/list",
    method: "get",
    params: param
  })
}
export interface BookTypeParam {
  name?: string
}
export function getBookType(param: BookTypeParam): Promise<Response<any>> {
  return request({
    url: "bookType/list",
    method: "get",
    params: param
  })
}
export interface InsertBookTypeBody {
  name: string
}
export function postInsertType(data: InsertBookTypeBody): Promise<Response<any>> {
  return request({
    url: "bookType/insert",
    method: "post",
    data: data
  })
}
export interface UpdateBookTypeParam {
  id: string
  name: string
}
export function putUpdateBookType(data: UpdateBookTypeParam): Promise<Response<any>> {
  return request({
    url: "bookType/update",
    method: "put",
    data: data
  })
}
export function deleteBookType(ids: number[]): Promise<Response<any>> {
  return request({
    url: "bookType/deleteByIds",
    method: "delete",
    params: {
      bIds: ids.join(",")
    }
  })
}
export function getNotice(): Promise<Response<PageResponse<any>>> {
  return request({
    url: "/notice",
    method: "get"
  })
}
export interface School {
  sid: string
  name: string
  type: SchoolType
  province: string
  city: string
  createTime: string
  updateTime: string
  remark: string
}
export interface SchoolPageParam extends PageParam {
  name?: string
  province: string
  city: string
}
// 学校类型，0：本科，1：专科，2：成人本科
export type SchoolType = 0 | 1 | 2
export const SchoolTypeList = ["本科", "专科", "成人本科"]
export function getSchoolList(param: SchoolPageParam): Promise<Response<PageResponse<School>>> {
  return request({
    url: "school/pageList",
    method: "get",
    params: param
  })
}
export interface InsertSchoolParam {
  name: string
  type: SchoolType
  province: string
  city: string
}
export function postInsertSchool(data: InsertSchoolParam): Promise<Response<boolean>> {
  return request({
    url: "school/insert",
    method: "post",
    data: data
  })
}
// 导入文件
export function importSchool(data: FormData): Promise<Response<boolean>>{
  return request({
    url: "school/import",
    method: "post",
    data: data,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  })
}
export interface UpdateSchoolParam {
  sid: string
  name: string
  type: SchoolType
  area?: string
}
export function putUpdateSchool(data: UpdateSchoolParam): Promise<Response<boolean>> {
  return request({
    url: "school/update",
    method: "put",
    data: data
  })
}
export function deleteSchool(sIds: string[]): Promise<Response<boolean>> {
  return request({
    url: "school/delete",
    method: "delete",
    params: {
      sIds: sIds.join(",")
    }
  })
}
